import { defineStore } from "pinia";
import systemApi from "@/api/system.js";

const configEnum = {
  1: "codeList",
  2: "linkList",
  3: "unitList",
};

export const useConfigStore = defineStore("config", () => {
  const configList = ref(null);
  const getConfigList = async () => {
    const { data } = await systemApi.getConfigList({
      pageNum: 1,
      pageSize: 999,
      status: 1,
    });
    const result = {
      codeList: [],
      linkList: [],
      unitList: [],
    };
    data.forEach((i) => {
      result[configEnum[i.linkType]].push(i);
    });
    configList.value = result;
  };

  return {
    configList,
    getConfigList,
  };
});
